﻿/**
 * Hiển thị thông tin chi tiết của khách hàng
 * Done
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using BLL;

namespace GUI.View
{
    public partial class ChiTietKhachHangControl : UserControl
    {
        public static int makhachhang;
        public static int _madiaoc;
        public static string diachi;
        public static string sodienthoai;
        public static string hoten;
        public static string email;

        private AppCommands _Commands;
        public AppCommands Commands
        {
            get { return _Commands; }
            set
            {
                if (value != _Commands)
                {
                    AppCommands oldValue = _Commands;
                    _Commands = value;
                    OnCommandsChanged(oldValue, value);
                }
            }
        }
        /// <summary>
        /// Called when Commands property has changed.
        /// </summary>
        /// <param name="oldValue">Old property value</param>
        /// <param name="newValue">New property value</param>
        protected virtual void OnCommandsChanged(AppCommands oldValue, AppCommands newValue)
        {
            if (newValue != null)
            {
                btnCancel.Command = newValue.ChiTietKhachHangCommands.Cancel;
            }
            else
            {
                btnCancel.Command = null;
            }
        }

        private readonly DiaOcBLL diaocbll;
        public ChiTietKhachHangControl()
        {
            InitializeComponent();
            diaocbll = new DiaOcBLL();
        }

        private void ChiTietKhachHangControl_Load(object sender, EventArgs e)
        {
            txtMaKhachHang.Text = makhachhang.ToString();
            txtDiaChi.Text = diachi;
            txtSoDT.Text = sodienthoai;
            txtHoTen.Text = hoten;
            txtEmail.Text = email;
            loaddanhsachdiaoc();
        }
        public void loaddanhsachdiaoc()
        {
            // TODO Check Cau truy van
            dataGridView_DiaOc.DataSource = (diaocbll.GetByID(_madiaoc)).Tables[0];
            for (int i = 0; i < dataGridView_DiaOc.Rows.Count; i++)
            {
                dataGridView_DiaOc.Rows[i].Cells[0].Value = i + 1;
            }
            dataGridView_DiaOc.Refresh();
        }
    }
}
